//${modelName}List.html
layui.use('table', function() {
    var table = layui.table,
        form = layui.form;
    //监听工具条
    table.on('tool(test)', function(obj){
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('确实要删除该数据吗？', function(index){
                $.ajax({
                    url:"/${visitUrl}/remove${className}?id="+data.id,
                    type:"POST",
                    dataType:"json",
                    success:function(datas){
                        if (datas.code != -1) {
                            obj.del();
                            layer.close(index);
                            layer.msg(datas.data);
                            table.reload("test");
                        } else {
                            layer.msg(datas.msg);
                        }
                    }
                });
            });
        } else if (obj.event === 'edit'){
            <#list updateList as column>
            $("#update${column.name}").val(data.${column.name});
            </#list>
            $('#update${className}').modal({ keyboard: true});
        }
    });
    var $ = layui.$, active = {
        add${className}: function(){ //新增
            $('#add${className}').modal({
                keyboard: true
            });
        },
        serach: function(){ //新增
            var searchtext = $('#searchtext');
            //执行重载
            table.reload('test', {
                page: {
                  curr: 1 //重新从第 1 页开始
                }
                ,where: {
            	    text: searchtext.val()
                }
            });
	    }
    };
    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    
    $('#add${className}').on('hidden.bs.modal', function () {
    	$('#add${className}Form')[0].reset();
    	$(this).removeData("bs.modal");
    })
    
    $('#update${className}').on('hidden.bs.modal', function () {
    	$('#update${className}Form')[0].reset();
    	$(this).removeData("bs.modal");
    })
});
